package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0153.java
 * @Author : WangRuoyu
 * @Date 2023/11/16 20:53
 */


public class Q0153 {
//    public int findMin(int[] nums) {
//        if (nums[0] < nums[nums.length - 1]) return nums[0];
//        int l = 0;
//        int r = nums.length - 1;
//        while (l < r) {
//            int mid = l + r >> 1;
//            if (nums[mid] < nums[0]) r = mid;
//            else l = mid + 1;
//        }
//        return nums[l];
//    }

    public int findMin(int[] nums) {
        if (nums[0] <= nums[nums.length - 1]) return nums[0];
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] < nums[0]) r = mid;
            else l = mid + 1;
        }
        return nums[l];
    }

    public static void main(String[] args) {
        Q0153 sl = new Q0153();
    }
}